class Solution {
public:
vector<int>arr;
unordered_map<int,int>mp;
int cmp(int x)
{
    if(mp.find(x)!=mp.end()) return mp[x];
    if(x==1) return mp[x]=0;
    if(x&1) return mp[x]=cmp(x*3+1)+1;
    else return mp[x]=cmp(x/2)+1;
}

    int getKth(int lo, int hi, int k) {
        for(int i=lo;i<=hi;i++)
            arr.push_back(i);
        sort(arr.begin(),arr.end(),[&] (int a,int b)
        {
            if(cmp(a)!=cmp(b)) return cmp(a)<cmp(b);
            else return a<b;
        });
        for(auto i : arr)
        cout<<i<<"  ";
        return arr[k-1];
    }
};